using System;

namespace AX.Utility
{
	public class PagerArgs
	{
		private int _CurPage;
		private int _CurCount;
		
		private int _TotalCount;
		private int _TotalPage;

		private int _CountPerPage;

		public PagerArgs()
		{
			_CurPage	  = 1;
			_CurCount     = 0;

			_TotalCount   = 0;
			_TotalPage	  = 1;

			_CountPerPage = 20;
		}

		public int iCurCount
		{
			get
			{
				return _CurCount;
			}
			set
			{
				_CurCount = value < 0 ? 0 : value;
			}
		}

		public int iTotalRecordCount
		{
			get
			{
				return _TotalCount;
			}
			set
			{
				_TotalCount = value < 0 ? 0 : value;
			}
		}

		public int iCountPerPage
		{
			get
			{
				return _CountPerPage;
			}
			set
			{
				_CountPerPage = value < 1 ? 1 : value;
			}
		}

		public int iCurPage
		{
			get
			{
				return _CurPage <= this.iTotalPage ? _CurPage : this.iTotalPage;
			}
			set
			{
				_CurPage = value < 1 ? 1 : value;
			}
		}

		public int iTotalPage
		{
			get
			{
				int iVal   = 0;
				_TotalPage = Math.DivRem(_TotalCount,_CountPerPage,out iVal);
				_TotalPage = (iVal == 0 ? _TotalPage : _TotalPage + 1);
				if ( _TotalPage == 0 ) _TotalPage++;
				return _TotalPage;
			}
		}
	}
}
